k=int(input())
if k>9999 or k<1000:
    print("0")
a=k//1000
b=k//100-a*10
c=k//10-k//100*10
d=k%10
s=0
big=0
print(a, b, c, d)
for e in range(1,a+1):
    if (a%e==0):
        s=s+1
if s==2 and a>big:
    big=a
    s=s-s
s=s-s
for g in range(1,b+1):
    if (b%g==0):
        s=s+1
if s==2 and b>big:
    big=b
    s=s-s
s=s-s
for f in range(1,c+1):
    if (c%f==0):
        s=s+1
if s==2 and c>big:
    big=c
    s=s-s
s=s-s
for u in range(1,d+1):
    if (d%u==0):
        s=s+1
if s==2 and d>big:
    big=d
    s=s-s
s=s-s
a=k%100
b=k//100
c=(k//10)-(k//1000*100)
print(b, c, a)
for h in range(1,a+1):
    if (a%h==0):
        k=s+1
if s==2 and a>big:
    big=a
    s=s-s
s=s-s
for l in range(1,b+1):
    if (b%l==0):
        s=s+1
if s==2 and b>big:
    big=b
    s=s-s
s=s-s
for j in range(1,c+1):
    if (c%j==0):
        s=s+1
if s==2 and c>big:
    big=c
    s=s-s
s=s-s
a=k//10
b=k%1000
print(a, b)
for m in range(1,a+1):
    if (a%m==0):
        s=s+1
if s==2 and a>big:
    big=a
    s=s-s
s=s-s
for x in range(1,b+1):
    if (b%x==0):
        s=s+1
if s==2 and b>big:
    big=b
    s=s-s
s=s-s
a=k
for v in range(1,a+1):
    if (a%v==0):
        s=s+1
if s==2 and a>big:
    big=a
    s=s-s
s=s-s
print(big)
